package top.korori.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.korori.common.model.PageData;
import top.korori.common.model.Result;
import top.korori.entity.req.SvHomeWorkGetReq;
import top.korori.entity.req.SvMyWorkGetReq;
import top.korori.entity.req.SvWorkAddReq;
import top.korori.entity.req.SvWorkGetReq;
import top.korori.entity.res.SvUserWorkRes;
import top.korori.entity.res.SvWorkRes;
import top.korori.service.ISvWorkService;

/**
 * 
 * 作品 前端控制器
 * 
 *
 * @author korori
 */

@Api(tags = "作品管理")
@RestController
@RequestMapping("/sv/work")

public class SvWorkController {

    @Autowired
    private ISvWorkService svWorkService;


    @ApiOperation("获取首页作品")
    @GetMapping("/getHoneWorks")
    public Result<PageData<SvUserWorkRes>> getHoneWorks(SvHomeWorkGetReq svHomeWorkGetReq){
        PageData<SvUserWorkRes> pageData = svWorkService.getHoneWorks(svHomeWorkGetReq);
        return Result.ok(pageData);
    }

    @ApiOperation("获取我的作品")
    @GetMapping("/getMyHomeList")
    public Result<PageData<SvWorkRes>> getMyHomeList(SvMyWorkGetReq svMyWorkGetReq){
        PageData<SvWorkRes> pageData = svWorkService.getUserHomeList(svMyWorkGetReq);
        return Result.ok(pageData);
    }

    @ApiOperation("获取用户作品")
    @GetMapping("/getUserList")
    public Result<PageData<SvWorkRes>> getUserList(SvWorkGetReq svWOrkGetReq){
        PageData<SvWorkRes> pageData = svWorkService.getUserHomeList(svWOrkGetReq);
        return Result.ok(pageData);
    }

    @ApiOperation("上传作品")
    @PostMapping("/push")
    public Result<SvUserWorkRes> push(@Validated @RequestBody SvWorkAddReq svWorkAddReq){
        SvUserWorkRes svUserWorkRes = svWorkService.push(svWorkAddReq);
        return Result.ok(svUserWorkRes);
    }

    @ApiOperation("删除自己作品")
    @DeleteMapping("/del/{workId}")
    public Result<PageData<SvUserWorkRes>> del(@PathVariable Long workId){
        svWorkService.delMyWork(workId);
        return Result.ok();
    }


}



















